import axios from "axios";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
axios.interceptors.request.use(
  config => {
    NProgress.start();
    console.log("登录开始，事件拦截...");
    return config;
  },
  err => {
    NProgress.done();
    return Promise.reject(err);
  }
);

axios.interceptors.response.use(
  response => {
    console.log("请求正确返回....");
    NProgress.done();
    return response;
  },
  error => {
    console.log("请求返回错误:", error);
    NProgress.done();
    if (error.response) {
      switch (error.response.status) {
        case 401:
          console.log("login status");
        case 404:
          console.log("后台接口没找到....404");
      }
    }
    return Promise.reject(error.response.data);
  }
);
